#include "jni.h"
#include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h"

#include <utils/misc.h>
#include <utils/Log.h>
#include <hardware/hardware.h>

extern "C" {
#include <stdio.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <math.h>
}

#define DEVICE "/dev/char_dev"

namespace android{

static int fd;
static jint init_native(JNIEnv *env, jobject clazz)
{
		fd = open(DEVICE, O_RDWR);
		if(fd < 0){
				ALOGD("cat't open device");
				return -1;
		}
		return 0;

}

static jint setLed_native(JNIEnv *env, jobject clazz,int status)
{
		int res;
		res = ioctl(fd,0,status);
		return 0;

}

static JNINativeMethod method_table[] = {

		{ "init_native", "()I", (void*)init_native },
		{ "setLed_native","(I)I", (void*)setLed_native },
};

int register_android_server_MyService(JNIEnv *env)
{
		return jniRegisterNativeMethods(env, "com/android/server/MyService",
						method_table, NELEM(method_table));
}

};
